<template>
  <div style="height: 50px;line-height: 50px;border-bottom:1px solid #ccc;display: flex ">
    <div style="width: 200px;padding-left: 30px;font-weight: bold;color: dodgerblue">共享存储柜管理系统</div>
    <div style="flex: 1"></div>
    <div style="width: 100px">
      <el-dropdown>
        <span class="el-dropdown-link">
          <br>
<!--          {{ user.username }} 张三-->
          {{ username }}
          <el-icon class="el-icon--right">
            <arrow-down />
          </el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="$router.push('/person')">个人信息</el-dropdown-item>
            <el-dropdown-item @click="logout">退出系统</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import { ArrowDown } from '@element-plus/icons-vue'
import router from "@/router";

export default {
  name: "Header",
  components:{
    ArrowDown
  },
  data() {
    return {
      username:"",
      }
    },
  methods: {
    // 退出时删除session中的user
    logout(){
      sessionStorage.clear();
      router.replace("/login");
    },
    getSession(){
      let name = sessionStorage.getItem("user")
      try {
        this.username = JSON.parse(name).username
      } catch (e) {
        this.$router.push("/login")
      }
    }
  },
  created() {

    this.getSession();
  }
}
</script>

<style scoped>
  .example-showcase .el-dropdown-link {
    cursor: pointer;
    color: var(--el-color-primary);
    display: flex;
    align-items: center;
  }
</style>
